<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" class="demo-form-inline">
      <i class="el-icon-search btn-search" @click="handleShowSearch()"></i>
      <div class="btn-box">
        <a
          class="el-button el-button--success el-button--medium"
          href="http://123.57.59.222:8081/api/file/business_opportunity_template.xlsx"
          type="primary"
          >模版下载</a
        >
        <el-upload
          action="http://123.57.59.222:8081/api/file/import_business_opportunity"
          :show-file-list="false"
          :on-success="handleImageSuccess"
          class="upload_image"
        >
          <el-button type="primary" v-show='roleName=="admin"'>导入</el-button>
        </el-upload>
      </div>

      <div v-show="showbtns == true" class="search-lf">
        <el-form-item label="战区">
          <el-select
            filterable
            v-model="listQuery.regionId"
            clearable
            @change="handleChangePro4($event)"
            placeholder="请选择"
          >
            <el-option
              v-for="item in regiosList"
              :key="item.id"
              :label="item.region"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="省份">
          <el-select
            filterable
            v-model="listQuery.provinceId"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in allProvinceList"
              :key="item.provinceId"
              :label="item.province"
              :value="item.provinceId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商机标题">
          <el-input
            v-model="listQuery.boTitle"
            placeholder="商机标题"
          ></el-input>
        </el-form-item>
        <el-form-item label="课程顾问">
          <el-input
            v-model="listQuery.chargeName"
            placeholder="课程顾问"
          ></el-input>
        </el-form-item>
        <el-form-item width="200px" label="客户名称">
          <el-input
            v-model="listQuery.customerName"
            placeholder="客户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="产品名称">
          <el-input
            v-model="listQuery.productName"
            placeholder="产品名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="getList()">查询</el-button>
          <el-upload
            :action="UploadUrl()"
            :show-file-list="false"
           
            :on-success="handleImageSuccess"
            class="upload_image"
          >
          </el-upload>
        </el-form-item>
      </div>
    </el-form>
    <el-table
      v-loading="listLoading"
      border
      height="650px"
      :data="list"
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column align="center" width="60px" label="序号">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="商机编号">
        <template slot-scope="{ row }">
          <span>{{ row.boNo }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="商机标题">
        <template slot-scope="{ row }">
          <span>{{ row.boTitle }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="战区">
        <template slot-scope="{ row }">
          <span>{{ row.regionName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="省区">
        <template slot-scope="{ row }">
          <span>{{ row.provinceName }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="负责人">
        <template slot-scope="{ row }">
          <span>{{ row.chargeName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width="200px" label="客户名称">
        <template slot-scope="{ row }">
          <span>{{ row.customerName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="产品名称">
        <template slot-scope="{ row }">
          <span>{{ row.productName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="产品编号">
        <template slot-scope="{ row }">
          <span>{{ row.productNo }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="产品数量">
        <template slot-scope="{ row }">
          <span>{{ row.productNumber }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="销售阶段">
        <template slot-scope="{ row }">
          <span>{{ row.stage }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="预计合同金额">
        <template slot-scope="{ row }">
          <span>{{ row.contractAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="预计签约日期">
        <template slot-scope="{ row }">
          <span>{{ row.signDate }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total >= 20"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getBusinessList } from "@/api/base_data";
import { baseUrl2 } from "@/api/remote-search";
import Pagination from "@/components/Pagination";
import{getProvinces} from  "@/api/supplier";
import { regiosList } from "@/api/user";
import { RegionsProvince } from "@/api/region";
export default {
  name: "userList",

  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: "男",
        0: "女",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      roleName:sessionStorage.getItem('memberName'),
      showbtns: false,
      regiosList: [], // 战区集合
      provinceList: [], //战区下面省份
      allProvinceList:[],//所有省份集合
      total: 0,
      uploadUrl: "",
      listLoading: true,
      listQuery: {
        access_token: sessionStorage.getItem("token"),
        page: 1,
        provinceName: "",

        regionName: "",

        pageSize: 20,
      },
      list: [],
    };
  },
  created() {
    this.getList();
    this.getallProvinceList();
  },
  computed: {},
  methods: {
      getallProvinceList() {
      getProvinces().then((res) => {
        this.allProvinceList = res.data.data;
      });
    },
    handleClose() {
      this.editDisabled = false;
    },
    handleShowSearch() {
      this.showbtns = !this.showbtns;
    },
    UploadUrl() {
      return  baseUrl2 + "/api/file/import_business_opportunity";
      
    },
    handleImageSuccess(file) {
      if (file.code == 200) {
        this.$message.success(file.message);
        this.getList();
      } else {
        this.$message.error(file.message);
      }
    },
    handleChangePro4(id) {
    

      RegionsProvince(id).then((res) => {
        this.provinceList = res.data.data;
      });
    },

    getList() {
      this.editDisabled = false;

      regiosList().then((res) => {
        this.regiosList = res.data.data;
      });
      this.listLoading = true;
      getBusinessList(this.listQuery)
        .then((response) => {
          this.list = response.data.data.rows;
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
  },
};
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
